import os
from mcp.server.fastmcp import FastMCP
import aiofiles
# Create an MCP server
mcp = FastMCP("Demo", log_level="INFO",host = "0.0.0.0",port=8081)

# 工具封装
@mcp.tool()
def get_company_tin(name:str) -> str:
    """get company tin"""
    if name.startswith('联通数据智能'):
        return '91110102MADD54BA28'
    else:
        return 'unknow'
# 资源封装
@mcp.resource(
    uri="file://data/company.txt",
    name="Company",
    description="获取",
    mime_type="text/plain")
async def Company_resource():
    # 打开文件获取数据，采用异步方式处理
    async with aiofiles.open("data/company.txt", mode="r", encoding="utf-8") as fp:
        content = await fp.read()
    return content

if __name__ == "__main__":
    # sse 
    mcp.run(transport="sse")
    # stdio 方式运行
    #mcp.run(transport="stdio")

